//
//  MLAlertController.m
//  QuickCure37
//
//  Created by 马文星 on 16/6/22.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "MLAlertController.h"

@implementation MLAlertController

/*!
 *  中间弹出窗户
 */
+ (void)alertWithVC:(UIViewController *)VC
              Title:(NSString *)title
            message:(NSString *)message
        cancelTitle:(NSString *)cancelTitle
        cancelBlock:(void(^)())cancelBlock
          sureTitle:(NSString *)sureTitle
          sureBlock:(void(^)())sureBlock{
    
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    //取消
    if (![cancelTitle isEqualToString:@""] || cancelTitle.length>0) {
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
            if (cancelBlock) {
                cancelBlock();
            }
        }];
        
        [alertVc addAction:cancelAction];
    }
    
    //确定
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        if (sureBlock) {
            sureBlock();
        }
    }];
    
    [alertVc addAction:sureAction];
    [VC presentViewController:alertVc animated:YES completion:nil];
}

/*!
 *  下面弹出窗户
 */
+ (void)alertSheetWithVC:(UIViewController *)VC
              Title:(NSString *)title
            message:(NSString *)message
        cancelTitle:(NSString *)cancelTitle
        cancelBlock:(void(^)())cancelBlock
          sureTitle:(NSString *)sureTitle
          sureBlock:(void(^)())sureBlock{
    
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
    
    //取消
    if (![cancelTitle isEqualToString:@""] || cancelTitle.length>0) {
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
            if (cancelBlock) {
                cancelBlock();
            }
        }];
        
        [alertVc addAction:cancelAction];
    }
    
    //确定
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        if (sureBlock) {
            sureBlock();
        }
    }];
    
    [alertVc addAction:sureAction];
    [VC presentViewController:alertVc animated:YES completion:nil];
}


@end
